Completed
Push — phpunit ( 7f2080...75f541 )
by Marcos
14:28 queued 10:45
created

angular.directive(ꞌclearBtnꞌ)   B

Complexity

Conditions 1
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 25
rs 8.8571
1
(function () {
2
	'use strict';
3
	/**
4
	 * @ngdoc directive
5
	 * @name passmanApp.directive:clearBtn
6
	 * @description
7
	 * # clearBtn
8
	 */
9
	angular.module('passmanApp')
10
		.directive('clearBtn', ['$parse', function ($parse) {
11
            return {
12
                link: function (scope, elm, attr) {
13
                    elm.wrap("<div style='position: relative'></div>");
14
                    var btn = '<span id=' + Math.round(Math.random() * 1000000000) + ' class="searchclear ng-hide fa fa-times-circle-o"></span>';
15
                    var angularBtn = angular.element(btn);
16
                    elm.after(angularBtn);
17
                    //clear the input
18
                    angularBtn.on("click", function () {
19
                        elm.val('').trigger("change");
20
                        $parse(attr.ngModel).assign(scope, '');
21
                        scope.$apply();
22
                    });
23
24
                    // show  clear btn  on focus
25
                    elm.bind('focus keyup change paste propertychange', function () {
26
                        if (elm.val() && elm.val().length > 0) {
27
                            angularBtn.removeClass("ng-hide");
28
                        } else {
29
                            angularBtn.addClass("ng-hide");
30
                        }
31
                    });
32
                }
33
            };
34
        }]);
35
}());
36
37
38